<script setup lang="ts">
import {formatDuration, mileageConversion, speedConvert, timeFormat} from '@/utils/gps/format'
import { ref, toRefs } from "vue";
import { recordSelect } from "@/utils/tool";
import {nanoid} from "nanoid";

const props = defineProps<{recordData: {stops: any[], trips: any[]}}>()
const playingRecord = ref("")
const { trips } = toRefs(props.recordData)

function parentClick(event){
  if(event.target.nodeName !== "LI") return
  recordSelect(event, playingRecord)
}
</script>

<template>
  <ul style="padding-right: 10px" @click="parentClick">
    <li v-for="(item, index) in trips" :key="index" class="item" :data-key="nanoid()">
      <span class="number">{{ index + 1 }}</span>
      <div class="info">
        <div class="detailed_info">
          <div>
            <p>{{ mileageConversion(item.distance) }}</p>
            <p>里程</p>
          </div>
          <div>
            <p>{{ timeFormat(item.duration) || 0}}</p>
            <p>行驶时长</p>
          </div>
          <div>
            <p>{{ speedConvert(item.maxSpeed) }}</p>
            <p>最大速度</p>
          </div>
          <div>
            <p>{{ speedConvert(item.averageSpeed) || "0/km"}}</p>
            <p>平均速度</p>
          </div>
        </div>
        <div class="position_info">
          <div>
            <i class="icon">始</i>
            <span>{{item.startTime}}</span>
            <p>{{item.startAddress}}</p>
          </div>
          <div>
            <i class="icon end">终</i>
            <span>{{item.endTime}}</span>
            <p>{{item.endAddress}}</p>
          </div>
        </div>
      </div>
    </li>
  </ul>
</template>

<style scoped>
.item {
  border: 1px solid #bdbdbd;
  border-radius: 5px;
  padding: 10px;
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}
.info {
  flex: 1;
  font-size: 12px;
  margin-left: 10px;
}
li{
  cursor: pointer;
}
li:hover{
  background-color: rgb(245, 247, 250);
}
li> *{
  pointer-events: none;
}
.on{
  background-color: rgb(204, 205, 206)!important;
}
.detailed_info{
  display: flex;
  width: 100%;
}
.detailed_info>div{
  width: 27%;
}
.detailed_info>div:first-child{
  width: 19%;
}
.detailed_info>div>p:first-child{
  color: rgb(75, 163, 255);
}
.icon{
  color: white;
  background: #5eff00;
  border-radius: 50%;
  padding: 2px;
  margin-right: 5px;
}
.end {
  background-color: red;
}
.position_info>div{
  margin-top: 8px;
}
</style>
